package com.xunyin.enums;


/**
 * @author jthong
 * @Description:设备分类
 * @Version 1.0.0
 * @Date 2019/12/26 16:18
 */
public enum DeviceClassifyEnum {
    /***
     * 采集器
     */
    CLASSIFY_COLLECT(1, "采集器"),
    /**
     * 控制器
     */
    CLASSIFY_CONTROL(2, "控制器");

    private final String name;
    private final int value;

    DeviceClassifyEnum(int value, String name) {
        this.name = name;
        this.value = value;
    }

    public int getValue() {
        return value;
    }

    public String getName() {
        return name;
    }

    public int getIndex() {
        return value;
    }

    public static DeviceClassifyEnum parse(Integer value) {
        if (value == null) {
            return throwParseException(value);
        }
        for (DeviceClassifyEnum e : DeviceClassifyEnum.values()) {
            if (e.getValue() == value) {
                return e;
            }
        }
        return throwParseException(value);
    }

    private static DeviceClassifyEnum throwParseException(Integer value) {
        throw new IllegalArgumentException(value + " can not parse to " + DeviceClassifyEnum.class.getName());
    }

    public static String getNameByValue(Integer value) {
        if (value == null) {
            return "";
        }
        for (DeviceClassifyEnum e : DeviceClassifyEnum.values()) {
            if (e.getValue() == value) {
                return e.getName();
            }
        }
        return "";
    }
}
